﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Organizer.pages
{
    public partial class AccountInfo : System.Web.UI.Page
    {
        #region Properties
        private int UserId { get { return Int32.Parse(Page.RouteData.Values["UserId"].ToString()); } }
        #endregion

        #region Events
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

            }
            catch (Exception ex)
            {
                FeedBackMsg(ex.Message.ToString(), (int)controls.AlertTypes.Error);
            }
        }
        protected void btnChangePass_Click(object sender, EventArgs e)
        {
            try
            {
                BLOrganizer.BLUsers BL = new BLOrganizer.BLUsers();
                bool Result = BL.ChangePassword(txtOldPass.Text, txtNewPass.Text, string.Empty, UserId);
                if (Result)
                {
                    FeedBackMsg("Password changed successfully.", (int)controls.AlertTypes.Sucess);
                    txtOldPass.Text = string.Empty;
                    txtNewPass.Text = string.Empty;
                    return;
                }
                FeedBackMsg("An error ocurred.", (int)controls.AlertTypes.Error);
            }
            catch (Exception ex)
            {
                FeedBackMsg(ex.Message.ToString(), (int)controls.AlertTypes.Error);
            }
        }
        protected void btnChangeUser_Click(object sender, EventArgs e)
        {
            try
            {
                BLOrganizer.BLUsers BL = new BLOrganizer.BLUsers();
                bool Result = BL.ChangeUsername(txtOldUser.Text, txtNewUser.Text, string.Empty, UserId);
                if (Result)
                {
                    FeedBackMsg("UserName changed successfully.", (int)controls.AlertTypes.Sucess);
                    txtOldUser.Text = string.Empty;
                    txtNewUser.Text = string.Empty;
                    return;
                }
                FeedBackMsg("An error ocurred.", (int)controls.AlertTypes.Error);
            }
            catch (Exception ex)
            {
                FeedBackMsg(ex.Message.ToString(), (int)controls.AlertTypes.Error);
            }
        }
        protected void btnReport_Click(object sender, EventArgs e)
        {
            try
            {
                BLOrganizer.BLReports BL = new BLOrganizer.BLReports();
                BL.AddReport(UserId, ddlReportType.SelectedValue, txtMessage.Text);
                FeedBackMsg("Report sent successfully.", (int)controls.AlertTypes.Sucess);
            }
            catch (Exception ex)
            {
                FeedBackMsg(ex.Message.ToString(), (int)controls.AlertTypes.Error);
            }
        }
        #endregion

        #region Methods
        private void FeedBackMsg(string Text, int AlertType)
        {
            try
            {
                Main Mn = (Main)Page.Master;
                Mn.FeedBackMsg(Text, AlertType);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }
}